//
// FILE NAME: CIDSpReco_Event.hpp
//
// AUTHOR: Dean Roddey
//
// CREATED: 01/10/2017
//
// COPYRIGHT: Charmed Quark Systems, Ltd @ 2019
//
//  This software is copyrighted by 'Charmed Quark Systems, Ltd' and
//  the author (Dean Roddey.) It is licensed under the MIT Open Source
//  license:
//
//  https://opensource.org/licenses/MIT
//
// DESCRIPTION:
//
//  This is the header a class that we use to pass along speech event information to
//  the client application. We pass along the following info:
//
//  1.  The name of the rule that was invoked. Not too useful most of the time since it
//      will just be the top level rule.
//  2.  A list of semantic values, in key/value form. The key is the semantic tag name
//      and the value is the invoked value of that tagged item. It also includes
//      confidence levels as well. One is always available and is a low, medium, high
//      indicator. The other may be available and is from -1.0 to 1.0. If not available,
//      it will be -1.0 and should be ignored, just use the other indicator.
//
//  The semantic value confidences that we get are fairly useless. What we really want is
//  the confidence values of the rules that drove them. This is almost impossible to do
//  automatically. So we allow the semantic values to themselves be used to provide a
//  rule to semantics mapping. A semantic value in the form Map_xxx is assumed to hold
//  the name of the sub-rule from which semantic value xxx was derived.
//
//  So we'll get the rule name out, remove the Map_ prefix, find that semantic value, and
//  update that one with the confidence levels of the rule.
//
// CAVEATS/GOTCHAS:
//
// LOG:
//
//  $_CIDLib_Log_$
//
#pragma once


#pragma CIDLIB_PACK(CIDLIBPACK)


// ---------------------------------------------------------------------------
//   CLASS: TCIDSpeechRecoEv
//  PREFIX: sprecev
// ---------------------------------------------------------------------------
class CIDSPRECOEXP TCIDSpeechRecoEv : public MFormattable
{
    public :
        // -------------------------------------------------------------------
        //  Constructors and Destructor
        // -------------------------------------------------------------------
        TCIDSpeechRecoEv();

        TCIDSpeechRecoEv
        (
            const   TCIDSpeechRecoEv&       sprecevSrc
        );

        ~TCIDSpeechRecoEv();


        // -------------------------------------------------------------------
        //  Public operators
        // -------------------------------------------------------------------
        TCIDSpeechRecoEv& operator=
        (
            const   TCIDSpeechRecoEv&       sprecevSrc
        );


        // -------------------------------------------------------------------
        //  Public, non-virtual methods
        // -------------------------------------------------------------------
        tCIDLib::TBoolean bFindSemVal
        (
            const   TString&                strName
            ,       TString&                strValue
        )   const;

        const tCIDSpReco::TSemList& colSemList() const;

        tCIDLib::TFloat4 f4RuleConfidence() const;

        const TString& strFindSemVal
        (
            const   TString&                strName
        )   const;

        const TString& strFindSemVal
        (
            const   TString&                strName
            ,       tCIDLib::TFloat4&       f4Confidence
        )   const;

        const TKeyNumPair* pknumFindSemVal
        (
            const   TString&                strName
        )   const;

        const TString& strRuleName() const;

        tCIDLib::TVoid Set
        (
            const   TString&                strRuleName
            , const tCIDLib::TFloat4        f4RuleConfidence
            , const tCIDSpReco::TSemList&   colSemList
            , const tCIDSpReco::TRuleList&  colRuleList
        );


    protected :
        // -------------------------------------------------------------------
        //  Protected, non-virtual methods
        // -------------------------------------------------------------------
        tCIDLib::TVoid FormatTo
        (
                    TTextOutStream&         strmDest
        )   const override;


    private :
        // -------------------------------------------------------------------
        //  Private, non-virtual methods
        // -------------------------------------------------------------------
        tCIDLib::TBoolean bFindSemIndex
        (
            const   TString&                strName
            ,       tCIDLib::TCard4&        c4At
        )   const;


        // -------------------------------------------------------------------
        //  Private data members
        //
        //  m_colSemList
        //      The list of semantic values that were generated by the matched rule,
        //      along with confidence values.
        //
        //  m_f4RuleConfidence
        //      The confidence level of the top level rule, which gives a general feel
        //      for the confidence. It's basically an average, so nothing will be higher
        //      than this. If it's low, the event is not of much interest.
        //
        //  m_strRuleName
        //      The name of the rule that was invoked.
        //
        //  m_tmAt
        //      The time at which this event was received, which we keep for debugging
        //      purposes. We format it out in FormatTo.
        // -------------------------------------------------------------------
        tCIDSpReco::TSemList    m_colSemList;
        tCIDLib::TFloat4        m_f4RuleConfidence;
        TString                 m_strRuleName;
        TTime                   m_tmAt;

        // In debug mode, we keep these so they can be formatted out for debugging
        #if CID_DEBUG_ON
        tCIDSpReco::TSemList    m_colRuleList;
        #endif
};

#pragma CIDLIB_POPPACK
